package com.xiashitech.apiservice.api;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.xiashitech.apiservice.service.IUserInfoService;
import com.xiashitech.interfaces.apiservice.dto.user.UserInfoRequest;
import com.xiashitech.interfaces.apiservice.dto.user.UserInfoResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 获取用户信息，agent的span补全用户信息使用
 */
@Controller
@RequestMapping(value = "/v1/agent")
@RequiredArgsConstructor(onConstructor =@_(@Autowired))
public class UserInfoController {
    private static final Log log = LogFactory.get();

    private final IUserInfoService authFactService;

    @RequestMapping(value = "/retrieveUserInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8" ,consumes = "application/json;charset=UTF-8")
    @ResponseBody
    public UserInfoResponse retrieveUserInfo(@RequestBody UserInfoRequest userRequest) {
        if(userRequest == null || userRequest.getId() == null || "".equals(userRequest.getId())) {
            return UserInfoResponse.builder().result(false).build();
        }
        UserInfoResponse userResponse = authFactService.retrieveUserInfo(userRequest);
        return userResponse;
    }
}
